//    Copyright (C) 2013  <lugocreation@gmail.com>
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
package org.jpgolay.me.piece;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;
import net.sf.jasperreports.engine.*;
import org.jpgolay.me.agency.Agency;
import org.jpgolay.me.buy.BuysPiece;
import org.jpgolay.me.customer.Customer;
import org.jpgolay.me.order.OrderRow;
import org.jpgolay.me.persistence.ObjectCRUD;
import org.jpgolay.me.sale.SalesBillPiece;
import org.jpgolay.me.sale.SalesPiece;
import org.jpgolay.me.salesperson.SalesPerson;
import org.jpgolay.me.supplier.Supplier;
import org.jpgolay.me.tax.Tax;
import org.jpgolay.me.util.Parameter;

public class PiecesPrintDataSource
        implements JRDataSource {

    public PiecesPrintDataSource(Agency agency, Object address, Object piece, SalesPerson salesPerson, ArrayList rowsList, Parameter param) {
        colCount = 0;
        zero = new BigDecimal("0.00");
        subTotal = new BigDecimal("0.00");
        this.agency = agency;
        this.salesPerson = salesPerson;
        this.rowsList = rowsList;
        this.param = param;
        if (piece instanceof SalesPiece) {
            salesPiece = (SalesPiece) piece;
            pieceType = getPieceType(22, salesPiece.getPrefix());
        } else if (piece instanceof SalesBillPiece) {
            salesBillPiece = (SalesBillPiece) piece;
            pieceType = getPieceType(25, salesBillPiece.getPrefix());
        } else if (piece instanceof BuysPiece) {
            buysPiece = (BuysPiece) piece;
            pieceType = getPieceType(24, buysPiece.getPrefix());
        }
        if (address instanceof Customer) {
            customer = (Customer) address;
            addressType = 27;
        } else if (address instanceof Supplier) {
            supplier = (Supplier) address;
            addressType = 9;
        }
        taxRate = getTaxRate();
        count = rowsList.size() * 76;
    }

    public boolean next()
            throws JRException {
        return count > 0;
    }

    public Object getFieldValue(JRField field)
            throws JRException {
        String fieldname = field.getName();
        String value = null;
        if ("col_ref".equals(fieldname)) {
            if (law.charAt(7) == '1') {
                value = getRowValueAt(0);
            }
        } else if ("col_designation".equals(fieldname)) {
            if (law.charAt(8) == '1') {
                value = getRowValueAt(1);
            }
        } else if ("col_batch".equals(fieldname)) {
            if (law.charAt(9) == '1') {
                value = getRowValueAt(2);
            }
        } else if ("col_quantity".equals(fieldname)) {
            if (law.charAt(10) == '1') {
                value = getRowValueAt(3);
            }
        } else if ("col_price_list".equals(fieldname)) {
            if (law.charAt(11) == '1') {
                value = getRowValueAt(4);
            }
        } else if ("col_discount".equals(fieldname)) {
            if (law.charAt(12) == '1') {
                value = getRowValueAt(5);
            }
        } else if ("col_unit_price".equals(fieldname)) {
            if (law.charAt(13) == '1') {
                value = getRowValueAt(6);
            }
        } else if ("col_total_price".equals(fieldname)) {
            if (law.charAt(14) == '1') {
                value = getRowValueAt(7);
            }
        } else if ("col_tax".equals(fieldname)) {
            if (law.charAt(15) == '1') {
                value = getRowValueAt(8);
            }
        } else if ("col_ref_txt".equals(fieldname)) {
            if (law.charAt(7) == '1') {
                value = "R\351f";
            }
        } else if ("col_designation_txt".equals(fieldname)) {
            if (law.charAt(8) == '1') {
                value = "D\351signation";
            }
        } else if ("col_batch_txt".equals(fieldname)) {
            if (law.charAt(9) == '1') {
                value = "Lot";
            }
        } else if ("col_quantity_txt".equals(fieldname)) {
            if (law.charAt(10) == '1') {
                value = "Qt";
            }
        } else if ("col_price_list_txt".equals(fieldname)) {
            if (pieceType < 5) {
                if (law.charAt(11) == '1') {
                    value = "Pv";
                }
            } else if (law.charAt(11) == '1') {
                value = "Pa";
            }
        } else if ("col_discount_txt".equals(fieldname)) {
            if (law.charAt(12) == '1') {
                value = "R (%)";
            }
        } else if ("col_unit_price_txt".equals(fieldname)) {
            if (law.charAt(13) == '1') {
                value = "Pu ht";
            }
        } else if ("col_total_price_txt".equals(fieldname)) {
            if (law.charAt(14) == '1') {
                value = "Mt ht";
            }
        } else if ("col_tax_txt".equals(fieldname)) {
            if (law.charAt(15) == '1') {
                value = "T";
            }
        } else if ("agency_company".equals(fieldname)) {
            if (law.charAt(20) == '1') {
                value = agency.getRaisonSociale();
            }
        } else if ("agency_status".equals(fieldname)) {
            if (law.charAt(21) == '1') {
                value = agency.getCivilite();
            }
        } else if ("agency_naf".equals(fieldname)) {
            if (agency.getNaf() != null && law.charAt(24) == '1') {
                value = "Naf : " + agency.getNaf();
            }
        } else if ("agency_siret".equals(fieldname)) {
            if (agency.getSiret() != null && law.charAt(23) == '1') {
                value = "Siret : " + agency.getSiret();
            }
        } else if ("agency_notes".equals(fieldname)) {
            if (law.charAt(22) == '1') {
                value = agency.getNotes();
            }
        } else if ("agency_addrLn1".equals(fieldname)) {
            if (law.charAt(27) == '1') {
                value = agency.getAdresseUn();
            }
        } else if ("agency_addrLn2".equals(fieldname)) {
            if (law.charAt(28) == '1') {
                value = agency.getAdresseDeux();
            }
        } else if ("agency_zip".equals(fieldname)) {
            if (law.charAt(29) == '1') {
                value = agency.getCp();
            }
        } else if ("agency_city".equals(fieldname)) {
            if (law.charAt(30) == '1') {
                value = agency.getVille();
            }
        } else if ("agency_country".equals(fieldname)) {
            if (law.charAt(0) == '1') {
                value = agency.getPays();
            }
        } else if ("agency_tel".equals(fieldname)) {
            if (agency.getTelephoneUn() != null && law.charAt(1) == '1') {
                value = "T\351l : " + agency.getTelephoneUn();
            }
        } else if ("agency_fax".equals(fieldname)) {
            if (agency.getFaxUn() != null && law.charAt(2) == '1') {
                value = "Fax : " + agency.getFaxUn();
            }
        } else if ("agency_email".equals(fieldname)) {
            if (agency.getEmail() != null && law.charAt(25) == '1') {
                value = "Email : " + agency.getEmail();
            }
        } else if ("agency_web".equals(fieldname)) {
            if (agency.getSiteWeb() != null && law.charAt(26) == '1') {
                value = "Site web : " + agency.getSiteWeb();
            }
        } else if ("address_company".equals(fieldname)) {
            if (addressType == 27) {
                value = customer.getRaisonSociale();
            } else {
                value = supplier.getRaisonSociale();
            }
        } else if ("address_status".equals(fieldname)) {
            if (addressType == 27) {
                value = customer.getCivilite();
            } else {
                value = supplier.getCivilite();
            }
        } else if ("address_addrLn1".equals(fieldname)) {
            if (addressType == 27) {
                if (pieceType == 2) {
                    if (customer.getAdresseLivrUn().equals("")) {
                        value = customer.getAdresseFactUn();
                    } else {
                        value = customer.getAdresseLivrUn();
                    }
                } else {
                    value = customer.getAdresseFactUn();
                }
            } else {
                value = supplier.getAdresseComUn();
            }
        } else if ("address_addrLn2".equals(fieldname)) {
            if (addressType == 27) {
                if (pieceType == 2) {
                    if (customer.getAdresseLivrUn().equals("")) {
                        value = customer.getAdresseFactDeux();
                    } else {
                        value = customer.getAdresseLivrDeux();
                    }
                } else {
                    value = customer.getAdresseFactDeux();
                }
            } else {
                value = supplier.getAdresseComDeux();
            }
        } else if ("address_zip".equals(fieldname)) {
            if (addressType == 27) {
                if (pieceType == 2) {
                    if (customer.getAdresseLivrUn().equals("")) {
                        value = customer.getCpFact();
                    } else {
                        value = customer.getCpLivr();
                    }
                } else {
                    value = customer.getCpFact();
                }
            } else {
                value = supplier.getCpCom();
            }
        } else if ("address_city".equals(fieldname)) {
            if (addressType == 27) {
                if (pieceType == 2) {
                    if (customer.getAdresseLivrUn().equals("")) {
                        value = customer.getVilleFact();
                    } else {
                        value = customer.getVilleLivr();
                    }
                } else {
                    value = customer.getVilleFact();
                }
            } else {
                value = supplier.getVilleCom();
            }
        } else if ("address_country".equals(fieldname)) {
            if (addressType == 27) {
                if (pieceType == 2) {
                    if (customer.getAdresseLivrUn().equals("")) {
                        if (law.charAt(3) == '1') {
                            value = customer.getPaysFact();
                        }
                    } else if (law.charAt(3) == '1') {
                        value = customer.getPaysLivr();
                    }
                } else if (law.charAt(3) == '1') {
                    value = customer.getPaysFact();
                }
            } else if (law.charAt(3) == '1') {
                value = supplier.getPaysCom();
            }
        } else if ("address_code".equals(fieldname)) {
            if (addressType == 27) {
                if (law.charAt(5) == '1') {
                    value = "Code : " + customer.getId();
                }
            } else if (law.charAt(5) == '1') {
                value = "Code : " + supplier.getId();
            }
        } else if ("address_tel".equals(fieldname)) {
            if (addressType == 27) {
                if (customer.getTelephone() != null && law.charAt(4) == '1') {
                    value = "T\351l : " + customer.getTelephone();
                }
            } else if (supplier.getTelephone() != null && law.charAt(4) == '1') {
                value = "T\351l : " + supplier.getTelephone();
            }
        } else if ("ref_piece".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    value = "COMMANDE " + salesPiece.getId();
                    break;

                case 2: // '\002'
                    value = "BL " + salesPiece.getId();
                    break;

                case 3: // '\003'
                    value = "FACTURE " + salesBillPiece.getId();
                    break;

                case 0: // '\0'
                    value = "DEVIS " + salesPiece.getId();
                    break;

                case 4: // '\004'
                    value = "AVOIR " + salesBillPiece.getId();
                    break;

                case 5: // '\005'
                    value = "COMMANDE " + buysPiece.getId();
                    break;

                case 6: // '\006'
                    value = "FACTURE " + buysPiece.getId();
                    break;

                case 7: // '\007'
                    value = "AVOIR " + buysPiece.getId();
                    break;
            }
        } else if ("ref_date".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    value = "DATE : " + salesPiece.getDate();
                    break;

                case 2: // '\002'
                    value = "DATE : " + salesPiece.getDate();
                    break;

                case 3: // '\003'
                    value = "DATE : " + salesBillPiece.getDate();
                    break;

                case 0: // '\0'
                    value = "DATE : " + salesPiece.getDate();
                    break;

                case 4: // '\004'
                    value = "DATE : " + salesBillPiece.getDate();
                    break;

                case 5: // '\005'
                    value = "DATE : " + buysPiece.getDate();
                    break;

                case 6: // '\006'
                    value = "DATE : " + buysPiece.getDate();
                    break;

                case 7: // '\007'
                    value = "DATE : " + buysPiece.getDate();
                    break;
            }
        } else if ("ref_salesPerson".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    if (law.charAt(6) == '1') {
                        value = "COMMERCIAL : " + salesPerson.getPrenom() + " " + salesPerson.getNom();
                    }
                    break;

                case 2: // '\002'
                    if (law.charAt(6) == '1') {
                        value = "COMMERCIAL : " + salesPerson.getPrenom() + " " + salesPerson.getNom();
                    }
                    break;

                case 3: // '\003'
                    if (law.charAt(6) == '1') {
                        value = "COMMERCIAL : " + salesPerson.getPrenom() + " " + salesPerson.getNom();
                    }
                    break;

                case 0: // '\0'
                    if (law.charAt(6) == '1') {
                        value = "COMMERCIAL : " + salesPerson.getPrenom() + " " + salesPerson.getNom();
                    }
                    break;

                case 4: // '\004'
                    if (law.charAt(6) == '1') {
                        value = "COMMERCIAL : " + salesPerson.getPrenom() + " " + salesPerson.getNom();
                    }
                    break;

                case 5: // '\005'
                    if (law.charAt(6) == '1') {
                        value = "COMMERCIAL : " + salesPerson.getPrenom() + " " + salesPerson.getNom();
                    }
                    break;

                case 6: // '\006'
                    if (law.charAt(6) == '1') {
                        value = "COMMERCIAL : " + salesPerson.getPrenom() + " " + salesPerson.getNom();
                    }
                    break;

                case 7: // '\007'
                    if (law.charAt(6) == '1') {
                        value = "COMMERCIAL : " + salesPerson.getPrenom() + " " + salesPerson.getNom();
                    }
                    break;
            }
        } else if ("tax_txt1".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    if (salesPiece.getTax1().compareTo(zero) != 0) {
                        value = "TVA1";
                    }
                    break;

                case 2: // '\002'
                    if (salesPiece.getTax1().compareTo(zero) != 0) {
                        value = "TVA1";
                    }
                    break;

                case 3: // '\003'
                    if (salesBillPiece.getTax1().compareTo(zero) != 0) {
                        value = "TVA1";
                    }
                    break;

                case 0: // '\0'
                    if (salesPiece.getTax1().compareTo(zero) != 0) {
                        value = "TVA1";
                    }
                    break;

                case 4: // '\004'
                    if (salesBillPiece.getTax1().compareTo(zero) != 0) {
                        value = "TVA1";
                    }
                    break;

                case 5: // '\005'
                    if (buysPiece.getTax1().compareTo(zero) != 0) {
                        value = "TVA1";
                    }
                    break;

                case 6: // '\006'
                    if (buysPiece.getTax1().compareTo(zero) != 0) {
                        value = "TVA1";
                    }
                    break;

                case 7: // '\007'
                    if (buysPiece.getTax1().compareTo(zero) != 0) {
                        value = "TVA1";
                    }
                    break;
            }
        } else if ("tax_txt2".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    if (salesPiece.getTax2().compareTo(zero) != 0) {
                        value = "TVA2";
                    }
                    break;

                case 2: // '\002'
                    if (salesPiece.getTax2().compareTo(zero) != 0) {
                        value = "TVA2";
                    }
                    break;

                case 3: // '\003'
                    if (salesBillPiece.getTax2().compareTo(zero) != 0) {
                        value = "TVA2";
                    }
                    break;

                case 0: // '\0'
                    if (salesPiece.getTax2().compareTo(zero) != 0) {
                        value = "TVA2";
                    }
                    break;

                case 4: // '\004'
                    if (salesBillPiece.getTax2().compareTo(zero) != 0) {
                        value = "TVA2";
                    }
                    break;

                case 5: // '\005'
                    if (buysPiece.getTax2().compareTo(zero) != 0) {
                        value = "TVA2";
                    }
                    break;

                case 6: // '\006'
                    if (buysPiece.getTax2().compareTo(zero) != 0) {
                        value = "TVA2";
                    }
                    break;

                case 7: // '\007'
                    if (buysPiece.getTax2().compareTo(zero) != 0) {
                        value = "TVA2";
                    }
                    break;
            }
        } else if ("tax_txt3".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    if (salesPiece.getTax3().compareTo(zero) != 0) {
                        value = "TVA3";
                    }
                    break;

                case 2: // '\002'
                    if (salesPiece.getTax3().compareTo(zero) != 0) {
                        value = "TVA3";
                    }
                    break;

                case 3: // '\003'
                    if (salesBillPiece.getTax3().compareTo(zero) != 0) {
                        value = "TVA3";
                    }
                    break;

                case 0: // '\0'
                    if (salesPiece.getTax3().compareTo(zero) != 0) {
                        value = "TVA3";
                    }
                    break;

                case 4: // '\004'
                    if (salesBillPiece.getTax3().compareTo(zero) != 0) {
                        value = "TVA3";
                    }
                    break;

                case 5: // '\005'
                    if (buysPiece.getTax3().compareTo(zero) != 0) {
                        value = "TVA3";
                    }
                    break;

                case 6: // '\006'
                    if (buysPiece.getTax3().compareTo(zero) != 0) {
                        value = "TVA3";
                    }
                    break;

                case 7: // '\007'
                    if (buysPiece.getTax3().compareTo(zero) != 0) {
                        value = "TVA3";
                    }
                    break;
            }
        } else if ("tax_txt4".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    if (salesPiece.getTax4().compareTo(zero) != 0) {
                        value = "TVA4";
                    }
                    break;

                case 2: // '\002'
                    if (salesPiece.getTax4().compareTo(zero) != 0) {
                        value = "TVA4";
                    }
                    break;

                case 3: // '\003'
                    if (salesBillPiece.getTax4().compareTo(zero) != 0) {
                        value = "TVA4";
                    }
                    break;

                case 0: // '\0'
                    if (salesPiece.getTax4().compareTo(zero) != 0) {
                        value = "TVA4";
                    }
                    break;

                case 4: // '\004'
                    if (salesBillPiece.getTax4().compareTo(zero) != 0) {
                        value = "TVA4";
                    }
                    break;

                case 5: // '\005'
                    if (buysPiece.getTax4().compareTo(zero) != 0) {
                        value = "TVA4";
                    }
                    break;

                case 6: // '\006'
                    if (buysPiece.getTax4().compareTo(zero) != 0) {
                        value = "TVA4";
                    }
                    break;

                case 7: // '\007'
                    if (buysPiece.getTax4().compareTo(zero) != 0) {
                        value = "TVA4";
                    }
                    break;
            }
        } else if ("tax_txt5".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    if (salesPiece.getTax5().compareTo(zero) != 0) {
                        value = "TVA5";
                    }
                    break;

                case 2: // '\002'
                    if (salesPiece.getTax5().compareTo(zero) != 0) {
                        value = "TVA5";
                    }
                    break;

                case 3: // '\003'
                    if (salesBillPiece.getTax5().compareTo(zero) != 0) {
                        value = "TVA5";
                    }
                    break;

                case 0: // '\0'
                    if (salesPiece.getTax5().compareTo(zero) != 0) {
                        value = "TVA5";
                    }
                    break;

                case 4: // '\004'
                    if (salesBillPiece.getTax5().compareTo(zero) != 0) {
                        value = "TVA5";
                    }
                    break;

                case 5: // '\005'
                    if (buysPiece.getTax5().compareTo(zero) != 0) {
                        value = "TVA5";
                    }
                    break;

                case 6: // '\006'
                    if (buysPiece.getTax5().compareTo(zero) != 0) {
                        value = "TVA5";
                    }
                    break;

                case 7: // '\007'
                    if (buysPiece.getTax5().compareTo(zero) != 0) {
                        value = "TVA5";
                    }
                    break;
            }
        } else if ("tax_rate1".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    if (salesPiece.getTax1().compareTo(zero) != 0) {
                        value = taxRate[0];
                    }
                    break;

                case 2: // '\002'
                    if (salesPiece.getTax1().compareTo(zero) != 0) {
                        value = taxRate[0];
                    }
                    break;

                case 3: // '\003'
                    if (salesBillPiece.getTax1().compareTo(zero) != 0) {
                        value = taxRate[0];
                    }
                    break;

                case 0: // '\0'
                    if (salesPiece.getTax1().compareTo(zero) != 0) {
                        value = taxRate[0];
                    }
                    break;

                case 4: // '\004'
                    if (salesBillPiece.getTax1().compareTo(zero) != 0) {
                        value = taxRate[0];
                    }
                    break;

                case 5: // '\005'
                    if (buysPiece.getTax1().compareTo(zero) != 0) {
                        value = taxRate[0];
                    }
                    break;

                case 6: // '\006'
                    if (buysPiece.getTax1().compareTo(zero) != 0) {
                        value = taxRate[0];
                    }
                    break;

                case 7: // '\007'
                    if (buysPiece.getTax1().compareTo(zero) != 0) {
                        value = taxRate[0];
                    }
                    break;
            }
        } else if ("tax_rate2".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    if (salesPiece.getTax2().compareTo(zero) != 0) {
                        value = taxRate[1];
                    }
                    break;

                case 2: // '\002'
                    if (salesPiece.getTax2().compareTo(zero) != 0) {
                        value = taxRate[1];
                    }
                    break;

                case 3: // '\003'
                    if (salesBillPiece.getTax2().compareTo(zero) != 0) {
                        value = taxRate[1];
                    }
                    break;

                case 0: // '\0'
                    if (salesPiece.getTax2().compareTo(zero) != 0) {
                        value = taxRate[1];
                    }
                    break;

                case 4: // '\004'
                    if (salesBillPiece.getTax2().compareTo(zero) != 0) {
                        value = taxRate[1];
                    }
                    break;

                case 5: // '\005'
                    if (buysPiece.getTax2().compareTo(zero) != 0) {
                        value = taxRate[1];
                    }
                    break;

                case 6: // '\006'
                    if (buysPiece.getTax2().compareTo(zero) != 0) {
                        value = taxRate[1];
                    }
                    break;

                case 7: // '\007'
                    if (buysPiece.getTax2().compareTo(zero) != 0) {
                        value = taxRate[1];
                    }
                    break;
            }
        } else if ("tax_rate3".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    if (salesPiece.getTax3().compareTo(zero) != 0) {
                        value = taxRate[2];
                    }
                    break;

                case 2: // '\002'
                    if (salesPiece.getTax3().compareTo(zero) != 0) {
                        value = taxRate[2];
                    }
                    break;

                case 3: // '\003'
                    if (salesBillPiece.getTax3().compareTo(zero) != 0) {
                        value = taxRate[2];
                    }
                    break;

                case 0: // '\0'
                    if (salesPiece.getTax3().compareTo(zero) != 0) {
                        value = taxRate[2];
                    }
                    break;

                case 4: // '\004'
                    if (salesBillPiece.getTax3().compareTo(zero) != 0) {
                        value = taxRate[2];
                    }
                    break;

                case 5: // '\005'
                    if (buysPiece.getTax3().compareTo(zero) != 0) {
                        value = taxRate[2];
                    }
                    break;

                case 6: // '\006'
                    if (buysPiece.getTax3().compareTo(zero) != 0) {
                        value = taxRate[2];
                    }
                    break;

                case 7: // '\007'
                    if (buysPiece.getTax3().compareTo(zero) != 0) {
                        value = taxRate[2];
                    }
                    break;
            }
        } else if ("tax_rate4".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    if (salesPiece.getTax4().compareTo(zero) != 0) {
                        value = taxRate[3];
                    }
                    break;

                case 2: // '\002'
                    if (salesPiece.getTax4().compareTo(zero) != 0) {
                        value = taxRate[3];
                    }
                    break;

                case 3: // '\003'
                    if (salesBillPiece.getTax4().compareTo(zero) != 0) {
                        value = taxRate[3];
                    }
                    break;

                case 0: // '\0'
                    if (salesPiece.getTax4().compareTo(zero) != 0) {
                        value = taxRate[3];
                    }
                    break;

                case 4: // '\004'
                    if (salesBillPiece.getTax4().compareTo(zero) != 0) {
                        value = taxRate[3];
                    }
                    break;

                case 5: // '\005'
                    if (buysPiece.getTax4().compareTo(zero) != 0) {
                        value = taxRate[3];
                    }
                    break;

                case 6: // '\006'
                    if (buysPiece.getTax4().compareTo(zero) != 0) {
                        value = taxRate[3];
                    }
                    break;

                case 7: // '\007'
                    if (buysPiece.getTax4().compareTo(zero) != 0) {
                        value = taxRate[3];
                    }
                    break;
            }
        } else if ("tax_rate5".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    if (salesPiece.getTax5().compareTo(zero) != 0) {
                        value = taxRate[4];
                    }
                    break;

                case 2: // '\002'
                    if (salesPiece.getTax5().compareTo(zero) != 0) {
                        value = taxRate[4];
                    }
                    break;

                case 3: // '\003'
                    if (salesBillPiece.getTax5().compareTo(zero) != 0) {
                        value = taxRate[4];
                    }
                    break;

                case 0: // '\0'
                    if (salesPiece.getTax5().compareTo(zero) != 0) {
                        value = taxRate[4];
                    }
                    break;

                case 4: // '\004'
                    if (salesBillPiece.getTax5().compareTo(zero) != 0) {
                        value = taxRate[4];
                    }
                    break;

                case 5: // '\005'
                    if (buysPiece.getTax5().compareTo(zero) != 0) {
                        value = taxRate[4];
                    }
                    break;

                case 6: // '\006'
                    if (buysPiece.getTax5().compareTo(zero) != 0) {
                        value = taxRate[4];
                    }
                    break;

                case 7: // '\007'
                    if (buysPiece.getTax5().compareTo(zero) != 0) {
                        value = taxRate[4];
                    }
                    break;
            }
        } else if ("tax_value1".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    if (salesPiece.getTax1().compareTo(zero) != 0) {
                        value = salesPiece.getTax1().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 2: // '\002'
                    if (salesPiece.getTax1().compareTo(zero) != 0) {
                        value = salesPiece.getTax1().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 3: // '\003'
                    if (salesBillPiece.getTax1().compareTo(zero) != 0) {
                        value = salesBillPiece.getTax1().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 0: // '\0'
                    if (salesPiece.getTax1().compareTo(zero) != 0) {
                        value = salesPiece.getTax1().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 4: // '\004'
                    if (salesBillPiece.getTax1().compareTo(zero) != 0) {
                        value = salesBillPiece.getTax1().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 5: // '\005'
                    if (buysPiece.getTax1().compareTo(zero) != 0) {
                        value = buysPiece.getTax1().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 6: // '\006'
                    if (buysPiece.getTax1().compareTo(zero) != 0) {
                        value = buysPiece.getTax1().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 7: // '\007'
                    if (buysPiece.getTax1().compareTo(zero) != 0) {
                        value = buysPiece.getTax1().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;
            }
        } else if ("tax_value2".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    if (salesPiece.getTax2().compareTo(zero) != 0) {
                        value = salesPiece.getTax2().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 2: // '\002'
                    if (salesPiece.getTax2().compareTo(zero) != 0) {
                        value = salesPiece.getTax2().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 3: // '\003'
                    if (salesBillPiece.getTax2().compareTo(zero) != 0) {
                        value = salesBillPiece.getTax2().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 0: // '\0'
                    if (salesPiece.getTax2().compareTo(zero) != 0) {
                        value = salesPiece.getTax2().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 4: // '\004'
                    if (salesBillPiece.getTax2().compareTo(zero) != 0) {
                        value = salesBillPiece.getTax2().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 5: // '\005'
                    if (buysPiece.getTax2().compareTo(zero) != 0) {
                        value = buysPiece.getTax2().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 6: // '\006'
                    if (buysPiece.getTax2().compareTo(zero) != 0) {
                        value = buysPiece.getTax2().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 7: // '\007'
                    if (buysPiece.getTax2().compareTo(zero) != 0) {
                        value = buysPiece.getTax2().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;
            }
        } else if ("tax_value3".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    if (salesPiece.getTax3().compareTo(zero) != 0) {
                        value = salesPiece.getTax3().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 2: // '\002'
                    if (salesPiece.getTax3().compareTo(zero) != 0) {
                        value = salesPiece.getTax3().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 3: // '\003'
                    if (salesBillPiece.getTax3().compareTo(zero) != 0) {
                        value = salesBillPiece.getTax3().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 0: // '\0'
                    if (salesPiece.getTax3().compareTo(zero) != 0) {
                        value = salesPiece.getTax3().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 4: // '\004'
                    if (salesBillPiece.getTax3().compareTo(zero) != 0) {
                        value = salesBillPiece.getTax3().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 5: // '\005'
                    if (buysPiece.getTax3().compareTo(zero) != 0) {
                        value = buysPiece.getTax3().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 6: // '\006'
                    if (buysPiece.getTax3().compareTo(zero) != 0) {
                        value = buysPiece.getTax3().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 7: // '\007'
                    if (buysPiece.getTax3().compareTo(zero) != 0) {
                        value = buysPiece.getTax3().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;
            }
        } else if ("tax_value4".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    if (salesPiece.getTax4().compareTo(zero) != 0) {
                        value = salesPiece.getTax4().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 2: // '\002'
                    if (salesPiece.getTax4().compareTo(zero) != 0) {
                        value = salesPiece.getTax4().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 3: // '\003'
                    if (salesBillPiece.getTax4().compareTo(zero) != 0) {
                        value = salesBillPiece.getTax4().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 0: // '\0'
                    if (salesPiece.getTax4().compareTo(zero) != 0) {
                        value = salesPiece.getTax4().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 4: // '\004'
                    if (salesBillPiece.getTax4().compareTo(zero) != 0) {
                        value = salesBillPiece.getTax4().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 5: // '\005'
                    if (buysPiece.getTax4().compareTo(zero) != 0) {
                        value = buysPiece.getTax4().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 6: // '\006'
                    if (buysPiece.getTax4().compareTo(zero) != 0) {
                        value = buysPiece.getTax4().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 7: // '\007'
                    if (buysPiece.getTax4().compareTo(zero) != 0) {
                        value = buysPiece.getTax4().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;
            }
        } else if ("tax_value5".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    if (salesPiece.getTax5().compareTo(zero) != 0) {
                        value = salesPiece.getTax5().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 2: // '\002'
                    if (salesPiece.getTax5().compareTo(zero) != 0) {
                        value = salesPiece.getTax5().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 3: // '\003'
                    if (salesBillPiece.getTax5().compareTo(zero) != 0) {
                        value = salesBillPiece.getTax5().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 0: // '\0'
                    if (salesPiece.getTax5().compareTo(zero) != 0) {
                        value = salesPiece.getTax5().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 4: // '\004'
                    if (salesBillPiece.getTax5().compareTo(zero) != 0) {
                        value = salesBillPiece.getTax5().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 5: // '\005'
                    if (buysPiece.getTax5().compareTo(zero) != 0) {
                        value = buysPiece.getTax5().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 6: // '\006'
                    if (buysPiece.getTax5().compareTo(zero) != 0) {
                        value = buysPiece.getTax5().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 7: // '\007'
                    if (buysPiece.getTax5().compareTo(zero) != 0) {
                        value = buysPiece.getTax5().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;
            }
        } else if ("total_gross_price_txt".equals(fieldname)) {
            value = "Total HT";
        } else if ("total_gross_price".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    value = salesPiece.getGrossPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 2: // '\002'
                    value = salesPiece.getGrossPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 3: // '\003'
                    value = salesBillPiece.getGrossPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 0: // '\0'
                    value = salesPiece.getGrossPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 4: // '\004'
                    value = salesBillPiece.getGrossPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 5: // '\005'
                    value = buysPiece.getGrossPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 6: // '\006'
                    value = buysPiece.getGrossPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 7: // '\007'
                    value = buysPiece.getGrossPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;
            }
        } else if ("total_shipping_txt".equals(fieldname)) {
            value = "Frais de port";
        } else if ("total_shipping".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    value = salesPiece.getShippingPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 2: // '\002'
                    value = salesPiece.getShippingPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 3: // '\003'
                    value = salesBillPiece.getShippingPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 0: // '\0'
                    value = salesPiece.getShippingPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 4: // '\004'
                    value = salesBillPiece.getShippingPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 5: // '\005'
                    value = buysPiece.getShippingPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 6: // '\006'
                    value = buysPiece.getShippingPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 7: // '\007'
                    value = buysPiece.getShippingPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;
            }
        } else if ("total_tax_txt".equals(fieldname)) {
            value = "Total TVA";
        } else if ("total_tax".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    value = salesPiece.getTotalTax().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 2: // '\002'
                    value = salesPiece.getTotalTax().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 3: // '\003'
                    value = salesBillPiece.getTotalTax().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 0: // '\0'
                    value = salesPiece.getTotalTax().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 4: // '\004'
                    value = salesBillPiece.getTotalTax().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 5: // '\005'
                    value = buysPiece.getTotalTax().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 6: // '\006'
                    value = buysPiece.getTotalTax().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 7: // '\007'
                    value = buysPiece.getTotalTax().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;
            }
        } else if ("total_price_txt".equals(fieldname)) {
            value = "Total TTC";
        } else if ("total_price".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    value = salesPiece.getNetPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 2: // '\002'
                    value = salesPiece.getNetPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 3: // '\003'
                    value = salesBillPiece.getNetPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 0: // '\0'
                    value = salesPiece.getNetPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 4: // '\004'
                    value = salesBillPiece.getNetPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 5: // '\005'
                    value = buysPiece.getNetPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 6: // '\006'
                    value = buysPiece.getNetPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;

                case 7: // '\007'
                    value = buysPiece.getNetPrice().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    break;
            }
        } else if ("total_part_payment_txt".equals(fieldname)) {
            if (law.charAt(16) == '1') {
                value = "Pay\351";
            }
        } else if ("total_part_payment".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    if (law.charAt(16) == '1') {
                        value = salesPiece.getPartPayment().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 2: // '\002'
                    if (law.charAt(16) == '1') {
                        value = salesPiece.getPartPayment().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 3: // '\003'
                    if (law.charAt(16) == '1') {
                        value = salesBillPiece.getPartPayment().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 0: // '\0'
                    if (law.charAt(16) == '1') {
                        value = salesPiece.getPartPayment().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 4: // '\004'
                    if (law.charAt(16) == '1') {
                        value = salesBillPiece.getPartPayment().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 5: // '\005'
                    if (law.charAt(16) == '1') {
                        value = buysPiece.getPartPayment().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 6: // '\006'
                    if (law.charAt(16) == '1') {
                        value = buysPiece.getPartPayment().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 7: // '\007'
                    if (law.charAt(16) == '1') {
                        value = buysPiece.getPartPayment().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;
            }
        } else if ("total_due_txt".equals(fieldname)) {
            if (law.charAt(17) == '1') {
                value = "Reste du";
            }
        } else if ("total_due".equals(fieldname)) {
            switch (pieceType) {
                case 1: // '\001'
                    if (law.charAt(17) == '1') {
                        value = salesPiece.getNetPrice().subtract(salesPiece.getPartPayment()).setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 2: // '\002'
                    if (law.charAt(17) == '1') {
                        value = salesPiece.getNetPrice().subtract(salesPiece.getPartPayment()).setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 3: // '\003'
                    if (law.charAt(17) == '1') {
                        value = salesBillPiece.getNetPrice().subtract(salesBillPiece.getPartPayment()).setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 0: // '\0'
                    if (law.charAt(17) == '1') {
                        value = salesPiece.getNetPrice().subtract(salesPiece.getPartPayment()).setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 4: // '\004'
                    if (law.charAt(17) == '1') {
                        value = salesBillPiece.getNetPrice().subtract(salesBillPiece.getPartPayment()).setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 5: // '\005'
                    if (law.charAt(17) == '1') {
                        value = buysPiece.getNetPrice().subtract(buysPiece.getPartPayment()).setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 6: // '\006'
                    if (law.charAt(17) == '1') {
                        value = buysPiece.getNetPrice().subtract(buysPiece.getPartPayment()).setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;

                case 7: // '\007'
                    if (law.charAt(17) == '1') {
                        value = buysPiece.getNetPrice().subtract(buysPiece.getPartPayment()).setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                    }
                    break;
            }
        } else if ("subTotal".equals(fieldname)) {
            if (subTotal.compareTo(zero) != 0) {
                value = "Report sous total : " + subTotal.setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
            }
        } else if ("unpaid".equals(fieldname)) {
            if (pieceType == 3) {
                law.charAt(18);
            }
        } else if ("due_date".equals(fieldname)) {
            if (pieceType == 3 && law.charAt(19) == '1') {
                value = "A payer jusqu'au : " + salesBillPiece.getDueDate();
            }
        } else if ("tax_rate_txt".equals(fieldname)) {
            value = "Taux";
        } else if ("tax_value_txt".equals(fieldname)) {
            value = "Montant";
        }
        count--;
        return value;
    }

    private int getPieceType(int piece, String prefix) {
        switch (piece) {
            case 22: // '\026'
                if (prefix.equals("D")) {
                    law = param.getPrintCustomerQuoteLaw();
                    return 0;
                }
                if (prefix.equals("C")) {
                    law = param.getPrintCustomerOrderLaw();
                    return 1;
                }
                if (prefix.equals("BL")) {
                    law = param.getPrintCustomerDeliveryLaw();
                    return 2;
                }
            // fall through

            case 25: // '\031'
                if (prefix.equals("F")) {
                    law = param.getPrintCustomerBillLaw();
                    return 3;
                }
                if (prefix.equals("A")) {
                    law = param.getPrintCustomerAssetLaw();
                    return 4;
                }
            // fall through

            case 24: // '\030'
                if (prefix.equals("C")) {
                    law = param.getPrintSupplierOrderLaw();
                    return 5;
                }
                if (prefix.equals("F")) {
                    law = param.getPrintSupplierBillLaw();
                    return 6;
                }
                if (prefix.equals("A")) {
                    law = param.getPrintSupplierAssetLaw();
                    return 7;
                }
            // fall through

            case 23: // '\027'
            default:
                return 0;
        }
    }

    private String getRowValueAt(int col) {
        orderRow = (OrderRow) rowsList.get(row);
        colCount++;
        if (colCount % 9 == 0) {
            row++;
        }
        switch (col) {
            case 0: // '\0'
                return orderRow.getArticleId();

            case 1: // '\001'
                return orderRow.getDesignation();

            case 2: // '\002'
                return orderRow.getLotId();

            case 3: // '\003'
                if (orderRow.getQuantite() == null) {
                    return null;
                } else {
                    return orderRow.getQuantite().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                }

            case 4: // '\004'
                if (orderRow.getPrixVente() == null) {
                    return null;
                } else {
                    return orderRow.getPrixVente().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                }

            case 5: // '\005'
                if (orderRow.getRemise() == null) {
                    return null;
                } else {
                    return orderRow.getRemise().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                }

            case 6: // '\006'
                if (orderRow.getPrixUnitaire() == null) {
                    return null;
                } else {
                    return orderRow.getPrixUnitaire().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                }

            case 7: // '\007'
                if (orderRow.getTotalHt() == null) {
                    return null;
                } else {
                    subTotal = subTotal.add(orderRow.getTotalHt());
                    return orderRow.getTotalHt().setScale(param.getMinimumDecimalNumber().intValue(), param.getRoundType().intValue()).toPlainString();
                }

            case 8: // '\b'
                if (orderRow.getTvaId() == null) {
                    return null;
                }
                if (orderRow.getTvaId().intValue() == 0) {
                    return null;
                } else {
                    return orderRow.getTvaId().toString();
                }
        }
        return null;
    }

    private String[] getTaxRate() {
        ObjectCRUD crud = new ObjectCRUD();
        java.util.Collection c = crud.readAll(null, 18);
        if (c != null) {
            ArrayList arrayList = new ArrayList(c);
            Iterator it = arrayList.iterator();
            String s[] = new String[arrayList.size()];
            Tax tax = null;
            for (int i = 0; it.hasNext(); i++) {
                tax = (Tax) it.next();
                s[i] = tax.getTaux().setScale(2).toPlainString();
            }

            return s;
        } else {
            return null;
        }
    }
    private Customer customer;
    private Supplier supplier;
    private Agency agency;
    private SalesPerson salesPerson;
    private SalesPiece salesPiece;
    private SalesBillPiece salesBillPiece;
    private BuysPiece buysPiece;
    private ArrayList rowsList;
    private int pieceType;
    private int addressType;
    private Parameter param;
    private int count;
    private int row;
    private int colCount;
    private OrderRow orderRow;
    private BigDecimal zero;
    private BigDecimal subTotal;
    private String taxRate[];
    private String law;
}
